<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <#include "/pubHeadStyleTree.html">
</head>
<body>
<form class="layui-form" action="" lay-filter="varItem" style="margin: 20px">
    <div class="layui-form-item">
        <b>说明：</b>
        <ul>
            <li>若为普通任务节点时，流程跳转至该任务，会自动产生该一个任务实例</li>
            <li>若为分发任务节点：流程跳至该任务时，会根据分发的个数，产生分发数的任务实例</li>
            <li>若为汇集任务节点：会根据分布的任务个数执行的路径，最终汇集生成一个任务实例</li>
        </ul>
    </div>
    <div class="layui-input-block">
         <input type="radio" name="bpmNodeType" value="0" lay-filter="bpmNodeType" title="普通任务节点" >
         <input type="radio" name="bpmNodeType" value="1" lay-filter="bpmNodeType" title="分发任务节点" >
    </div>
<div class="layui-form-item">
    <div id="joinTaskKey" style="display:none">
        <br/><label><b>请选择汇总节点 : </b></label>
        <select name="joinTaskKey" lay-filter="bpmNodeType">
            <option value="">请选择汇总节点</option>
            <#list nodeMap?keys as key>
            <option value="${key}">${nodeMap[key]}</option>
            </#list>
        </select>
        <input type="hidden" name="joinTaskName" id="joinTaskName" <#if bpmNodeSet??>value="${bpmNodeSet.joinTaskName}"</#if>/>
    </div>
    <div>
        <input type="hidden" name="procDefId"       value="${procDefId}" />
        <input type="hidden" name="nodeId"          value="${nodeId}" />
    </div>
</div>
<div class="layui-btn-container" style="width:100%;position: absolute;bottom: 5px; left: 0px;text-align: center;">
    <button class="layui-btn" lay-submit lay-filter="varForm">保存</button>
    <button class="layui-btn layui-btn-danger" id="close">取消</button>
</div>
</form>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','layer', 'form','setter'], function(){
        var $ =layui.$,
            setter=layui.setter,
            layer=layui.layer,
            form=layui.form;
        //index
        var index = parent.layer.getFrameIndex(window.name);
        //下拉框回显
        var bpmNodeSetType = '${bpmNodeSet.nodeType}';
        if(bpmNodeSetType!='') {
            $("input:radio[value='"+bpmNodeSetType+"']").attr('checked', 'true');
            if(bpmNodeSetType==1){
                $("#joinTaskKey").css("display","block");
                $("select[name='joinTaskKey']").val('${bpmNodeSet.joinTaskKey}');
            }else{
                $("#joinTaskKey").css("display","none");
            }
        }else{
            $("input:radio[value='0']").attr('checked', 'true');
        }
        form.render('radio');
        form.render('select');

        //radio监听事件
        form.on('radio(bpmNodeType)',function (obj) {
            if(obj.value==1){
                $("#joinTaskKey").css("display","block");
            }else{
                $("#joinTaskKey").css("display","none");
            }
        });
        //select监听事件
        form.on('select(bpmNodeType)',function (obj) {
            $(obj.elem).children("option").each(function () {
                if($(this).val()==obj.value){
                    $("input[name='joinTaskName']").val($(this).text());
                    return ;
                };
            })
        });
        //保存
        form.on('submit(varForm)',function (data) {
                var _field=data.field;
                var _data = {
                    procDefId:_field.procDefId,
                    nodeId:_field.nodeId,
                    nodeType:_field.bpmNodeType
                }
            if(_data.nodeType==1){
                _data.joinTaskKey=_field.joinTaskKey;
                _data.joinTaskName=_field.joinTaskName;
            }
            $.ajax({
                url:serverPath.workflowPath + setter.workflowLinkPath + "bpmNodeSet/saveFlowForkJoin"
                , type:"post"
                , data:_data
                , dataType:"json"
                ,async: false
                , success:function(res) {
                    if (res.code == 0 || res.code == '0') {
                        parent.layer.close(index);
                        parent.layer.msg(res.msg, {time: 5000, icon: 6})
                    } else {
                        parent.layer.msg(res.msg, {time: 5000, icon: 5})
                    }
                }
                ,error: function (XMLHttpRequest, textStatus, errorThrown) {
                    window.parent.layer.alert("保存失败！" + XMLHttpRequest.status);
                }
            });
        });
        //关闭弹窗
        $("#close").click(function () {
            parent.layer.close(index);
        })
    })
</script>
<style>
    .layui-form-checkbox[lay-skin=primary]{
        padding-left: 0px;
    }
</style>
</body>
</html>